<?php
/**
 * websocket 客户端、访问路径等 管理类
 */

namespace Swostar\Server\WebSocket;

class Connections
{
    /**
     * 记录用户的连接
     * [
     *     fd => [
     *         'path' => '',
     *         'userinfo' => [],
     *     ]
     * ]
     * @var array
     */
    protected static $connections = [];


    public static function init($fd, $request)
    {
        self::$connections[$fd]['path'] = $request->server['path_info'];
        self::$connections[$fd]['request'] = $request;
    }

    public static function get($fd = null)
    {
        return $fd ? self::$connections[$fd] : self::$connections;
    }

    public static function delete($fd)
    {
        unset(self::$connections[$fd]);
    }
}
